//
//  MainLiveAlertUserClassNumView.m
//  v8090Video
//
//  Created by 陈建 on 2018/9/3.
//  Copyright © 2018年 BlueWind. All rights reserved.
//

#import "MainLiveAlertUserClassNumView.h"


#define btnHeight 70

@interface MainLiveAlertUserClassNumView ()

@property (nonatomic, strong) NSArray *btnContentArray;

@property (nonatomic, strong) NSArray *detailNameArray;

@property (nonatomic, strong) UIView *lineView;

@end

@implementation MainLiveAlertUserClassNumView

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.isHiddenLine = YES;
        [self setupSubViews];
    }
    return self;
}
+ (CGFloat)userInfoViewHeight{
    return btnHeight;
}
- (void)setupSubViews{
    CGFloat btnW = kScreenWidth/4.0;
    NSMutableArray *btnArr = [NSMutableArray array];
    for (NSInteger i = 0; i< 4; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = 200 + i;
        btn.titleLabel.font = [UIFont systemFontOfSize:14.f];
        [btn setTitleColor:kRGBColor(233, 50, 35) forState:UIControlStateNormal];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.titleLabel.numberOfLines = 2;
        
        [self addSubview:btn];
        [btnArr addObject:btn];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(i * btnW);
            make.top.equalTo(self);
            make.height.equalTo(@(btnHeight));
            make.width.equalTo(@(btnW));
        }];
    }
    self.btnContentArray = btnArr;

    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self);
        make.height.equalTo(@0.5);
    }];
    
}

- (void)setUpUserClassNumWith:(NSArray *)dataArray{
    for (NSInteger i = 0; i < self.detailNameArray.count; i++) {
        UIButton *btn = (UIButton *)self.btnContentArray[i];
        NSString *firstS = dataArray[i];
        NSString *title = [NSString stringWithFormat:@"%@\n%@",firstS,self.detailNameArray[i]];
   
        
        btn.titleLabel.attributedText = [self attrWithTitle:title withFistTitle:firstS];
        [btn setAttributedTitle: [self attrWithTitle:title withFistTitle:firstS] forState:UIControlStateNormal];
        
    }
}




- (void)btnClick:(UIButton *)sender{
    NSInteger tag = sender.tag - 200;
    NSLog(@"+++%ld",tag);
    if (self.TapClassNumBtnBlock) {
        self.TapClassNumBtnBlock(tag);
    }
}

- (void)setIsHiddenLine:(BOOL)isHiddenLine{
    _isHiddenLine = isHiddenLine;
    self.lineView.hidden = isHiddenLine;
}

- (NSArray *)detailNameArray{
    if (!_detailNameArray) {
        _detailNameArray = [NSArray array];
        _detailNameArray = @[@"今日获得糖果",@"已获得糖果",@"合约收益",@"我的钱包"];
    }
    return _detailNameArray;
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#D9D9D9"];
        [self addSubview:_lineView];
    }
    return _lineView;
}
- (NSMutableAttributedString *)attrWithTitle:(NSString *)title withFistTitle:(NSString *)firstS{
    NSMutableAttributedString *muAttr = [[NSMutableAttributedString alloc] initWithString:title];
    
    NSMutableParagraphStyle*paragraphStyle = [NSMutableParagraphStyle new];
    [paragraphStyle setLineSpacing:8];
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [muAttr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, title.length)];
    [muAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, firstS.length)];
    [muAttr addAttribute:NSForegroundColorAttributeName value:kRGBColor(233, 50, 35) range:NSMakeRange(0, firstS.length)];
    
    [muAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(firstS.length, title.length - firstS.length)];
    [muAttr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:kDetailTextGrayBlackColor] range:NSMakeRange(firstS.length, title.length - firstS.length)];
    return muAttr;
}
@end
